import {
    Dispatch
} from 'redux';

import ajax from './../../http';

import * as types from './../types/browse';

interface LimitPara {
    limit?: number,
    lastId: number | string
}

interface BrowsePara extends LimitPara {
    orderBy: string
}

export default {
    //获取 people 列表
    [types.getBrowseList](
        payload: BrowsePara
    ) {
        return async (dispatch: Dispatch) => {
            const {
                lastId,
                limit = 30
            } = payload;

            const _para = {
                limit: limit,
                lastId: lastId,
                orderBy:`near`,
                searchType: 'browse',
                startCond: 'user_search_result_id >'
            }

            try {
                const list = await ajax.get(
                    `users`,
                    _para
                )
                dispatch({
                    type: types.getBrowseList,
                    data: {
                        isPush:!!lastId,
                        queryList: list,
                    }
                })
                return list;
            }
            catch (e) {
                return Promise.reject(e)
            }
        }
    }
}